package com.aaa.order.mq;

import com.aaa.entity.AccountOrder;
import com.aaa.entity.Order;
import com.aaa.order.OrderApplication;
import com.aaa.order.dao.AccountOrderDao;
import com.aaa.order.dao.OrderDao;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author JYH
 * @version 1.0
 * @date 2023/3/15 16:11
 */
@Component
public class DeadOrderLisenter {
    @Autowired
    private OrderDao orderDao;

    @RabbitListener(queues = {"order_deadQueue"})
    public void getMsg(String msg, Channel channel){
//        long deliveryTag = msg.getMessageProperties().getDeliveryTag();
//        byte[] body = msg.getBody();
//        System.out.println("body = " + new String(body));
//        String s = new String(body);
//        try {
        //System.out.println("获取到的订单编号是 " + msg);
        Order order = orderDao.selectById(msg);
        if (order.getState()==1){
            orderDao.concelOrder(msg);
        }
//            channel.basicNack(deliveryTag,true,true);
    }
//        catch (Exception e){
//            e.printStackTrace();
//            try {
//                channel.basicNack(deliveryTag,true,true);
//            }catch (IOException e1){
//                e1.printStackTrace();
//            }
//        }

//    }
}
